package cn.kb05;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;

/*
 * @author
 * @Description   原平均分为81.29，加2分之后的结果
 * @date
 * */
public class Bianli {
    public static void main(String[] args) {
        //ArrayList
        ArrayList arr = new ArrayList();
        arr.add(1);
        arr.add(2);
        arr.add("a");
        arr.add('b');

        System.out.println("ArrayList三种遍历");
        //循环遍历
        for (int i = 0; i <  arr.size(); i++) {
            System.out.print(arr.get(i)+"  ");
        }
        System.out.println();
          //增强for
        for (Object obj:arr) {
            System.out.print(obj+"  ");
        }
        System.out.println();
           //迭代器遍历
        Iterator iter = arr.iterator();
        while(iter.hasNext()){
            System.out.print(iter.next()+"  ");
        }


        //LinkedList
        System.out.println();
        System.out.println("LinkedList三种遍历");
        LinkedList link = new LinkedList();
        link.offer("abc");

        link.add('a');
        link.add('a');
        link.add('a');


        link.addLast(3);
        link.addFirst(1);
        link.add('a');
        for (int i = 0; i < link.size(); i++) {
            System.out.print(link.get(i)+"  ");
        }
        System.out.println();
        for (Object obj:link
        ) {
            System.out.print(obj+"  ");
        }
        System.out.println();
        Iterator iter1 = link.iterator();
        while(iter1.hasNext()){
            System.out.print(iter1.next()+"  ");
        }

        //Set的遍历
        System.out.println();
        System.out.println("Set的两种遍历");
        HashSet set =  new HashSet();
        set.addAll(link);
        //增强for
        for (Object obj:set) {
            System.out.print(obj+"  ");
        }
        System.out.println();
        //迭代器遍历
        Iterator iter2 = set.iterator();
        while (iter2.hasNext()){
            System.out.print(iter2.next()+"  ");
        }

    }
}
